<template>
  <div>
    <BasicTable @register="registerTable"   @row-click="clickThenCheck" @selection-change="clickThenCheck">
      <template #toolbar>
        <a-button type="primary" size="small" @click="getSelectRowList">会员详情</a-button>
        <a-button type="primary" size="small" @click="handleCreate">新增会员</a-button>
        <a-button type="primary" size="small" @click="handleCreate">会员注销</a-button>
        <a-button type="primary" size="small" @click="handleCreate">解绑微信</a-button>
        <a-button type="primary" size="small" @click="handleCreate">换绑公众号</a-button>
        <a-button type="primary" size="small" @click="handleCreate">换绑手机</a-button>
        <a-button type="primary" size="small" @click="handleCreate">重置密码</a-button>
        <a-button type="primary" size="small" @click="handleCreate">新会员导入</a-button>
        <a-button type="primary" size="small" @click="handleCreate">会员导出</a-button>
        <a-button type="primary" size="small" @click="handleCreate">修改</a-button>
        <a-button type="primary" size="small" @click="handleCreate">会员卡管理</a-button>
        <a-button type="primary" size="small" @click="handleCreate">常用旅客</a-button>
        <a-button type="primary" size="small" @click="handleCreate">常用联系人</a-button>
        <a-button type="primary" size="small" @click="handleCreate">常用地址</a-button>
        <a-button type="primary" size="small" @click="handleCreate">我的订单</a-button>
        <a-button type="primary" size="small" @click="handleCreate">投诉建议</a-button>
        <a-button type="primary" size="small" @click="handleCreate">积分管理</a-button>
        <a-button type="primary" size="small" @click="handleCreate">操作日志</a-button>
      </template>
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              icon: 'clarity:note-edit-line',
              onClick: handleEdit.bind(null, record),
            },
            {
              icon: 'ant-design:delete-outlined',
              color: 'error',
              popConfirm: {
                title: '是否确认删除',
                confirm: handleDelete.bind(null, record),
              },
            },
          ]"
        />
      </template>
    </BasicTable>
    <UserDrawer @register="registerDrawer" @success="handleSuccess"/>
    <UserDetailModal @register="registerUserDetailModel"/>
  </div>
</template>
<script lang="ts">
  import {defineComponent} from 'vue';

  import {BasicTable, TableAction, useTable} from '/@/components/Table';
  import {userPage} from './api';
  import {useDrawer} from '/@/components/Drawer';
  import UserDrawer from './UserDrawer.vue';
  import {useModal} from '/@/components/Modal';
  import UserDetailModal from './UserDetailModal.vue';
  import {columns, searchFormSchema} from './data';

  export default defineComponent({
    name: 'userManagement',
    components: {BasicTable, UserDrawer, TableAction, UserDetailModal},
    setup() {
      const [registerDrawer, {openDrawer}] = useDrawer();
      const [registerTable, {reload, getSelectRowKeys}] = useTable({
        title: '',
        api: userPage,
        columns,
        formConfig: {
          labelWidth: 120,
          schemas: searchFormSchema,
        },
        useSearchForm: true,
        showTableSetting: true,
        bordered: true,
        showIndexColumn: true,
        searchInfo: {handlerName: 'appUserInfoListHandler'},
        rowKey: 'userId',
        clickToRowSelect: true,

        actionColumn: {
          width: 80,
          title: '操作',
          dataIndex: 'action',
          slots: {customRender: 'action'},
          fixed: undefined,
        },
        rowSelection: {
          type: 'radio'
        },
      });
      const [registerUserDetailModel, {openModal: openUserDetailModel}] = useModal();

      function getSelectRowList() {
        console.log(getSelectRowKeys());
      }

      function handleCreate() {
        openDrawer(true, {
          isUpdate: false,
        });
      }

      function clickThenCheck() {
        console.info('===================')
      }


      function handleEdit(record: Recordable) {
        openDrawer(true, {
          record,
          isUpdate: true,
        });
      }

      function handleDelete(record: Recordable) {
        console.log(record);
      }

      function handleSuccess() {
        reload();
      }

      return {
        registerTable,
        registerDrawer,
        registerUserDetailModel,
        openUserDetailModel,
        getSelectRowList,
        handleCreate,
        handleEdit,
        handleDelete,
        handleSuccess,
        clickThenCheck
      };
    },
  });
</script>
